<%@ page language="java" pageEncoding="UTF-8"%>
<div class="modal-body">
  <script id="container" name="content" type="text/plain"></script>
  <div class="box-footer text-right">
	<!--以下两种方式提交验证,根据所需选择-->
	<button type="button" class="btn btn-default" data-btn-type="cancel" onclick="dialog_close()">取消</button>
	<button type="button" class="btn btn-primary" data-btn-type="save" onclick="saveHtml()">提交</button>
</div>
</div>

<!-- baidu ueditor-->
<script src="${pageContext.request.contextPath}/ueditor/ueditor.config.js"></script>
<script src="${pageContext.request.contextPath}/ueditor/ueditor.all.js"></script>
<script src="${pageContext.request.contextPath}/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
  UE.delEditor('container');
  var editor = UE.getEditor('container');
  /* editor.setHeight(800); */

  /*UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
  console.log(UE.Editor.prototype._bkGetActionUrl);
  UE.Editor.prototype.getActionUrl = function(action) {
    if (action == 'uploadimage' || action == 'uploadscrawl' || action == 'uploadimage'
            || action == 'uploadvideo' || action == 'uploadfile') {
      console.log('action='+action);
      return '${basePath}/upload/uploadfile';
    }else {
      console.log('action1='+action);
      return this._bkGetActionUrl.call(this, action);
    }
  }*/
//  editor.setOpt('imageUrl','${basePath}/upload/uploadfile');

  editor.addListener("ready", function () {
	  editor.setHeight(600);
    // editor准备好之后才可以使用
      var id = Dtable_project.rows('.selected').data()[0].id;
	  $.ajax({
		  url: '../../tbl_project/'+id,
		  type : 'get',
		  async : false,
		  contentType: "application/json; charset=utf-8",
		  dataType: "json",
		  success: function(json) {
			  console.log(json);
			  editor.setContent(json.data.html);
		  }
	});
  });

  //button event
  function saveHtml() {
		var url = "../../tbl_project/saveHtml";
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: {
				  html: editor.getContent(),
				  id:Dtable_project.rows('.selected').data()[0].id
			  },
			  //contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function(json) {
				 global.alert(json.message);
				 //$("#project_main").load("project/project_list.html");
				 dialog_close();
				 if(fn){fn();}
			  }
		});
  }
  
  function dialog_close(){
		global.dialog.close()
	}
</script>
</html>
